home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_bas / vbprnt20.zip / VBPRINT.DOC < prev    next >
Text File  |  1996-05-31  |  30KB  |  737 lines

  1. VBPRINT Library v2.00 written by Robert Simpson (Black Castle Software, LLC)
  2.  
  3. This program has been released to the public domain.  No warranties are
  4. expressed or implied.  Use at your own risk.
  5.  
  6. ---Overview---
  7. This DLL allows your Visual Basic applications to have better control over the
  8. printer device.  It seems to be the one area MS has consistently forgotten in
  9. VB.
  10.  
  11. By far the easiest method for changing printer orientation, paper settings,
  12. trays, color and etc is to use the DEVMODE structure and make calls to the
  13. printer driver's ExtDeviceMode() function.  Unfortunately this particular
  14. function resides in the printer driver itself and VB cannot load that driver
  15. and call pointers to functions within it.  Therefore, I have written a set of
  16. printer control functions which do exactly that.  In addition, using the 
  17. VBResetDC() function, you can make changes to the printer orientation and 
  18. other settings during a print session (even if you're using VB's Printer
  19. object).
  20.  
  21. One of the problems of course is that not all DEVMODE structures are created
  22. equal.  Depending on the printer, the driver may append its own private data
  23. to the end of a DEVMODE structure, which further complicates the VB interface.
  24. The trick here is that all calls to VBPRINT use a special DEVMODE structure
  25. which I've modified for use with VB (hence called the VBDEVMODE).  This
  26. VBDEVMODE allows the VB Programmer access to all the important items in the
  27. DEVMODE structure and still allows the printer to have its own private area.
  28.  
  29.  
  30. ---Features---
  31. Ability to get/set the Windows default printer
  32. Ability to list all the installed printers
  33. Allows VB to call the ExtDeviceMode() function of a printer
  34. Also allows VB to call the DeviceCapabilities() function of a printer
  35. Has special VB version of ResetDC() to change printer settings on the fly
  36. Uses a special DEVMODE structure specifically tailored for VB
  37. Can convert a VBDEVMODE structure from and to a VB String so it can be easily
  38. saved to disk and restored later
  39. What this means is, you now have an easy method for changing print orientation
  40. and any other printer settings through the use of the VBDEVMODE structure.
  41.  
  42.  
  43. ---Flavors of this Library (and why there ARE flavors!!)---
  44. This library comes in 3 flavors so just about any VB programmer can use it
  45.  
  46. A VB3 version of the DLL (which is compatible with VB4/16-bit)
  47. A VB4/16-bit version (which is NOT compatible with VB3!!)
  48. A VB4/32-bit version (who's functions are identical to the VB4/16-bit version)
  49.  
  50. Why is the VB3 version compatible with VB4 and the VB4 version not compatible
  51. with VB3?  I decided that I wanted the VB4/32-bit and VB4/16-bit versions to
  52. be functionally identical, which meant that I had to allow for the fact that
  53. VB4/32-bit uses UNICODE strings (16-bits per character), and therefore I could
  54. not always write directly into memory because VB4 often does some unwanted
  55. translations when making function calls.
  56.  
  57. The particular function affected (and the ONLY one affected) is the
  58. VBDeviceCapabilities() function.  In the VB3 version, there is only ONE
  59. command, VBDeviceCapabilities().  Often this function returns an array of data
  60. to the user, which is no problem in VB3 or VB4/16-bit, you just pass the first
  61. dimension of the array (such as Names$(0) ) and the DLL can write all the
  62. elements of the array since they're stored linearly in memory.
  63. NOT SO in VB4/32-bit!!  If you pass Names$(0) to a DLL, VB4 translates it from
  64. UNICODE to ANSI and gives you a new pointer to JUST THAT DIMENSION, leaving me
  65. no place to put the rest of the items that are supposed to go in the array.
  66.  
  67. Therefore in order to make your VB code portable from 16-bits to 32-bits,
  68. the VB4 versions of the DLL have a VBDeviceCapArray() function, which is
  69. just an Alias to "VBDeviceCapabilities" but one that explicitly requires an
  70. array variable, which you would pass as Names$() (with NO numbers between the
  71. parens!).
  72.  
  73. So if you are porting a VB3 program to use the NEW VB4 VBPRNTxx library, you
  74. will need to replace commands such as:
  75.  
  76.   i = VBDeviceCapabilities(DefPrinter$,DC_PAPERNAMES,Names$(0),inDEV)
  77.  
  78. to the new format for arrays in the VB4 version:
  79.  
  80.   i = VBDeviceCapArray(DefPrinter$,DC_PAPERNAMES,Names$(),inDEV)
  81.  
  82. **THIS IS THE ONLY DIFFERENCE IN FUNCTION CALLS**
  83.  
  84.  
  85. ---Using this DLL with the Printer Object---
  86. Most printing in VB goes through the Printer object, which leaves much to be
  87. desired.  Normally in the Windows API you can pass a DEVMODE structure when
  88. you create a device context, which makes life much easier--you can include all
  89. your custom printer settings in the device open sequence and not have to
  90. bother with a bunch of subsequent Escape() functions.
  91. The VB Printer object doesn't allow this convenience.  Therefore if you must
  92. use the VB Printer object, you have two options:
  93. (Assuming you've already got a VBDEVMODE structure filled in with your desired
  94. settings)
  95. #1
  96. Use the Printer object's .hDC property and call VBResetDC() with the filled-
  97. in VBDEVMODE structure.  This is the easiest method...or...
  98.  
  99. #2
  100. Call VBExtDeviceMode() and get the printer's current settings (see the
  101. functions reference for instructions on doing this)
  102.  
  103. Make another call to VBExtDeviceMode() with your DEVMODE structure and tell
  104. the printer to use these settings as the new default settings.
  105.  
  106. Use the Printer object to your heart's content
  107.  
  108. When finished, one more call to VBExtDeviceMode() with the old default
  109. settings, restoring them back to the original.
  110.  
  111. Using the utilities in this DLL, you'll be able to change printers, use them
  112. in ways you were unable to do previously, and change back to the default
  113. printer all without an annoying dialog box or having to prompt the user.
  114.  
  115.  
  116. ---The DEVMODE structure---
  117. If you're familiar with the DEVMODE structure, this one should look strikingly
  118. similar.
  119.  
  120. Type DEVMODE_TYPE
  121.   dmDeviceName As String * 32 ' VB4/32 uses an array of Byte
  122.   dmSpecVersion As Integer
  123.   dmDriverVersion As Integer
  124.   dmSize As Integer
  125.   dmDriverExtra As Integer
  126.   dmFields As Long
  127.   dmOrientation As Integer
  128.   dmPaperSize As Integer
  129.   dmPaperLength As Integer
  130.   dmPaperWidth As Integer
  131.   dmScale As Integer
  132.   dmCopies As Integer
  133.   dmDefaultSource As Integer
  134.   dmPrintQuality As Integer
  135.   dmColor As Integer
  136.   dmDuplex As Integer
  137.   dmYResolution As Integer
  138.   dmTTOption As Integer
  139.   dmPrivate As String
  140. End Type
  141.  
  142. The 32-bit version adds several items to the above structure, and uses arrays
  143. of Byte instead of fixed-length strings because of the fact that strings are
  144. stored internally in UNICODE format (which means they're twice as large)
  145.  
  146.  
  147. The following is an exerpt from the Win3.1 SDK describing the elements of the
  148. DEVMODE structure:
  149.  
  150. dmDeviceName
  151. Specifies the name of the device the driver supports--for example, "PCL/HP
  152. LaserJet" in the case of the Hewlett-Packard LaserJet. Each driver has a
  153. unique string.
  154.  
  155. dmSpecVersion
  156. Specifies the version number of the DEVMODE structure. For Windows version
  157. 3.1, this value should be 0x30A.
  158.  
  159. dmDriverVersion
  160. Specifies the printer driver version number assigned by the printer driver
  161. developer.
  162.  
  163. dmSize
  164. Specifies the size, in bytes, of the DEVMODE structure. (This value does not
  165. include the optional dmDriverData member for device-specific data, which can
  166. follow the structure.) If an application manipulates only the driver-
  167. independent portion of the data, it can use this member to find out the length
  168. of the structure without having to account for different versions.
  169.  
  170. dmDriverExtra
  171. Specifies the size, in bytes, of the optional dmDriverData member for device-
  172. specific data, which can follow the structure. If an application does not use
  173. device-specific information, it should set this member to zero.
  174.  
  175. dmFields
  176. Specifies a set of flags that indicate which of the remaining members in the
  177. DEVMODE structure have been initialized. It can be any combination (or it can
  178. be none) of the following values:
  179.  
  180. Constant        Value
  181.  
  182. DM_ORIENTATION        0x0000001L 
  183. DM_PAPERSIZE        0x0000002L 
  184. DM_PAPERLENGTH        0x0000004L 
  185. DM_PAPERWIDTH        0x0000008L 
  186. DM_SCALE        0x0000010L 
  187. DM_COPIES        0x0000100L 
  188. DM_DEFAULTSOURCE    0x0000200L 
  189. DM_PRINTQUALITY        0x0000400L 
  190. DM_COLOR        0x0000800L 
  191. DM_DUPLEX        0x0001000L 
  192. DM_YRESOLUTION        0x0002000L 
  193. DM_TTOPTION        0x0004000L 
  194.  
  195. A printer driver supports only those members that are appropriate for the
  196. printer technology.
  197.  
  198. dmOrientation
  199. Specifies the orientation of the paper. It can be either DMORIENT_PORTRAIT or
  200. DMORIENT_LANDSCAPE.
  201.  
  202. dmPaperSize
  203. Specifies the size of the paper to print on. This member may be set to zero if
  204. the length and width of the paper are specified by the dmPaperLength and
  205. dmPaperWidth members, respectively. Otherwise, the dmPaperSize member can be
  206. set to one of the following predefined values:
  207.  
  208. Value            Meaning
  209.  
  210. DMPAPER_FIRST        DMPAPER_LETTER 
  211. DMPAPER_LETTER        Letter, 8 1/2 x 11 in. 
  212. DMPAPER_LETTERSMALL    Letter Small, 8 1/2 x 11 in. 
  213. DMPAPER_TABLOID        Tabloid, 11 x 17 in. 
  214. DMPAPER_LEDGER        Ledger, 17 x 11 in. 
  215. DMPAPER_LEGAL        Legal, 8 1/2 x 14 in. 
  216. DMPAPER_STATEMENT    Statement, 5 1/2 x 8 1/2 in. 
  217. DMPAPER_EXECUTIVE    Executive, 7 1/2 x 10 1/2 in. 
  218. DMPAPER_A3        A3, 297 x 420 mm 
  219. DMPAPER_A4        A4, 210 x 297 mm 
  220. DMPAPER_A4SMALL        A4 Small, 210 x 297 mm 
  221. DMPAPER_A5        A5, 148 x 210 mm 
  222. DMPAPER_B4        B4, 250 x 354 mm 
  223. DMPAPER_B5        B5, 182 x 257 mm 
  224. DMPAPER_FOLIO        Folio, 8 1/2 x 13 in. 
  225. DMPAPER_QUARTO        Quarto, 215 x 275 mm 
  226.  
  227. DMPAPER_10X14        10 x 14 in. 
  228. DMPAPER_11X17        11 x 17 in. 
  229. DMPAPER_NOTE        Note, 8 1/2 x 11 in. 
  230. DMPAPER_ENV_9        Envelope #9, 3 7/8 x 8 7/8 in. 
  231. DMPAPER_ENV_10        Envelope #10, 4 1/8 x 9 1/2 in. 
  232. DMPAPER_ENV_11        Envelope #11, 4 1/2 x 10 3/8 in. 
  233. DMPAPER_ENV_12        Envelope #12, 4 1/2 x 11 in. 
  234. DMPAPER_ENV_14        Envelope #14, 5 x 11 1/2 in. 
  235. DMPAPER_CSHEET        C size sheet 
  236. DMPAPER_DSHEET        D size sheet 
  237. DMPAPER_ESHEET        E size sheet 
  238. DMPAPER_ENV_DL        Envelope DL, 110 x 220 mm 
  239. DMPAPER_ENV_C3        Envelope C3, 324 x 458 mm 
  240. DMPAPER_ENV_C4        Envelope C4, 229 x 324 mm 
  241. DMPAPER_ENV_C5        Envelope C5, 162 x 229 mm 
  242.  
  243. DMPAPER_ENV_C6        Envelope C6, 114 x 162 mm 
  244. DMPAPER_ENV_C65        Envelope C65, 114 x 229 mm 
  245. DMPAPER_ENV_B4        Envelope B4, 250 x 353 mm 
  246. DMPAPER_ENV_B5        Envelope B5, 176 x 250 mm 
  247. DMPAPER_ENV_B6        Envelope B6, 176 x 125 mm 
  248. DMPAPER_ENV_ITALY    Envelope, 110 x 230 mm 
  249. DMPAPER_ENV_MONARCH    Envelope Monarch, 3 7/8 x 7 1/2 in. 
  250. DMPAPER_ENV_PERSONAL    Envelope, 3 5/8 x 6 1/2 in. 
  251. DMPAPER_FANFOLD_US    U.S. Standard Fanfold, 14 7/8 x 11 in. 
  252. DMPAPER_FANFOLD_STD_GERMAN    German Standard Fanfold, 8 1/2 x 12 in. 
  253. DMPAPER_FANFOLD_LGL_GERMAN    German Legal Fanfold, 8 1/2 x 13 in. 
  254.  
  255. DMPAPER_LAST        German Legal Fanfold, 8 1/2 x 13 in. 
  256. DMPAPER_USER        User-defined 
  257.  
  258. dmPaperLength
  259. Specifies a paper length, in tenths of a millimeter. This parameter overrides
  260. the paper length specified by the dmPaperSize member, either for custom paper
  261. sizes or for such devices as dot-matrix printers that can print on a variety
  262. of page sizes.
  263.  
  264. dmPaperWidth
  265. Specifies a paper width, in tenths of a millimeter. This parameter overrides
  266. the paper width specified by the dmPaperSize member.
  267.  
  268. dmScale
  269. Specifies the factor by which the printed output is to be scaled. The
  270. apparent page size is scaled from the physical page size by a factor of
  271. dmScale/100. For example, a letter-size paper with a dmScale value of 50 would
  272. contain as much data as a page of size 17 by 22 inches because the output text
  273. and graphics would be half their original height and width.
  274.  
  275. dmCopies
  276. Specifies the number of copies printed if the device supports multiple-page
  277. copies.
  278.  
  279. dmDefaultSource
  280. Specifies the default bin from which the paper is fed. The application can
  281. override this value by using the GETSETPAPERBINS escape. This member can be
  282. one of the following values:
  283.  
  284. DMBIN_AUTO        DMBIN_LOWER 
  285. DMBIN_CASSETTE        DMBIN_MANUAL 
  286. DMBIN_ENVELOPE        DMBIN_MIDDLE 
  287. DMBIN_ENVMANUAL        DMBIN_ONLYONE 
  288. DMBIN_FIRST        DMBIN_SMALLFMT 
  289. DMBIN_LARGECAPACITY    DMBIN_TRACTOR 
  290. DMBIN_LARGEFMT        DMBIN_UPPER 
  291. DMBIN_LAST    
  292.  
  293. A range of values is reserved for device-specific bins. To be consistent with
  294. initialization information, the GETSETPAPERBINS and ENUMPAPERBINS escapes use
  295. these values.
  296.  
  297. dmPrintQuality
  298. Specifies the printer resolution. Following are the four predefined device-
  299. independent values:
  300.  
  301. DMRES_HIGH     (-4) 
  302. DMRES_MEDIUM     (-3) 
  303. DMRES_LOW     (-2) 
  304. DMRES_DRAFT     (-1) 
  305.  
  306. If a positive value is given, it specifies the number of dots per inch (DPI)
  307. and is therefore device-dependent.  If the printer initializes the
  308. dmYResolution member, the dmPrintQuality member specifies the x-resolution
  309. of the printer, in dots per inch.
  310.  
  311. dmColor
  312. Specifies whether a color printer is to render color or monochrome output.
  313. Possible values are:
  314.  
  315. DMCOLOR_COLOR         (1) 
  316. DMCOLOR_MONOCHROME     (2) 
  317.  
  318. dmDuplex
  319. Specifies duplex (double-sided) printing for printers capable of duplex
  320. printing. This member can be one of the following values:
  321.  
  322. DMDUP_SIMPLEX     (1) 
  323. DMDUP_HORIZONTAL (2) 
  324. DMDUP_VERTICAL     (3) 
  325.  
  326. dmYResolution
  327. Specifies the y-resolution of the printer, in dots per inch. If the printer
  328. initializes this member, the dmPrintQuality member specifies the x-resolution
  329. of the printer, in dots per inch.
  330.  
  331. dmTTOption
  332. Specifies how TrueType fonts should be printed. It can be one of the following
  333. values:
  334.  
  335. Value           Meaning
  336.  
  337. DMTT_BITMAP    Print TrueType fonts as graphics. This is the default action
  338. for dot-matrix printers.
  339.  
  340. DMTT_DOWNLOAD    Download TrueType fonts as soft fonts. This is the default
  341. action for Hewlett-Packard printers that use Printer Control Language (PCL).
  342.  
  343. DMTT_SUBDEV    Substitute device fonts for TrueType fonts. This is the
  344. default action for PostScript printers.
  345.  
  346.  
  347. -----------------------------------------------------------------------------
  348. -----------------------------------------------------------------------------
  349. -----------------------------------------------------------------------------
  350.  
  351.  
  352. VBPRINT Library Function Reference:
  353.  
  354.  
  355. ---General Notes---
  356. The VBDeviceCapabilities() function call is different in the VB3 version of
  357. the DLL.  While VB4.0/16-bit is fully compatible with it and your VB3 apps
  358. will port flawlessly to VB4/16-bit, you will have to make some modifications
  359. to your code if you want to port it to VB4/32-bit.
  360.  
  361. However, if you are writing in native VB4 and not coming from VB3, DO NOT USE
  362. VBPRINT.DLL IF YOU DON'T HAVE TO!  Use the VB4 versions instead so that your
  363. 16-bit and 32-bit VB programs will be fully compatible.
  364.  
  365.  
  366. ---Functions---
  367.  
  368. Declare:
  369. Declare Function VBGetPrinters() As String
  370.  
  371. Example Usage:
  372. NextPrinter$ = VBGetPrinters()
  373.  
  374. Description:
  375. This function works similar to the Dir$() VB function.  Each time you call
  376. VBGetPrinters() it returns the next printer installed on the computer.  It
  377. will return a NULL string when it has reached the end of the list.
  378.  
  379. Returns:
  380. String
  381. The format for printers returned with this function (and the format for all
  382. functions requiring a printername) is:
  383. <printername> on <port>
  384.  
  385. Example:
  386. Epson Stylus Pro on LPT1:
  387. -----------------------------------------------------------------------------
  388.  
  389. Declare:
  390. Declare Function VBGetDefPrinter() As String
  391.  
  392. Example Usage:
  393. DefPrinter$ = VBGetDefPrinter()
  394.  
  395. Returns:
  396. String
  397. This function returns the Windows default printer in the same format as the
  398. VBGetPrinters() function above.
  399. -----------------------------------------------------------------------------
  400.  
  401. Declare:
  402. Declare Function VBSetDefPrinter(DefPrinter As String) As Integer
  403.  
  404. Example Usage:
  405. i = VBSetDefPrinter(DefPrinter$)
  406.  
  407. Description:
  408. This function sets a new Windows Default printer.
  409.  
  410. Returns:
  411. Integer
  412.  0 = (False) Unable to determine the printer's driver (typically printer not
  413.      installed)
  414. -1 = (True) Success
  415. -----------------------------------------------------------------------------
  416.  
  417. Declare:
  418. Declare Function VBGetDriverFromName Lib "vbprint.dll" (printername As String) 
  419. As String
  420.  
  421. Example Usage:
  422. Driver$ = VBGetDriverFromName(DefPrinter$)
  423.  
  424. Description:
  425. This function returns the driver associated with a printer.  This is the
  426. actual .DRV file that handles the printer.  It's of little use other than for
  427. reference purposes only.
  428.  
  429. Returns:
  430. String
  431. -----------------------------------------------------------------------------
  432.  
  433. Declare:
  434. Declare Function VBDevModeToStr Lib "vbprint.dll" (inDev As DEVMODE_TYPE) As
  435. String
  436.  
  437. Example Usage:
  438. Devmode$ = VBDevModeToStr(dmINPUT)
  439.  
  440. Description:
  441. This function converts a VBDEVMODE structure to a string so that it can be
  442. easily saved to disk and/or restored later.
  443.  
  444. Returns
  445. String
  446. -----------------------------------------------------------------------------
  447.  
  448. Declare:
  449. Declare Function VBStrToDevMode Lib "vbprint.dll" (dmString As String, outDev
  450. As DEVMODE_TYPE) As Integer
  451.  
  452. Example Usage:
  453. i = VBStrToDevMode(Devmode$,dmOUTPUT)
  454.  
  455. Description:
  456. This function takes a string created with VBDevModeToStr() and dumps it into 
  457. the specified VBDEVMODE structure, thereby restoring it back so you can once
  458. again easily edit it.
  459.  
  460. Returns:
  461. Integer
  462. True  = Success
  463. False = Fail (of course)
  464. -----------------------------------------------------------------------------
  465.  
  466. Declare:
  467. Declare Function VBExtDeviceMode Lib "vbprint.dll" (ByVal hWnd As Integer,
  468. printername As String, inDev As DEVMODE_TYPE, outDev As DEVMODE_TYPE, ByVal
  469. fMode As Integer) As Integer
  470.  
  471. Inputs:
  472.   hWnd        The parent window if you wish to open the printer's setup
  473.                 dialog.  Can be 0 otherwise.
  474.   printername   The name and port of the printer to configure (formatted the
  475.                 same as all the other functions that refer to printers)
  476.   inDev         Input VBDEVMODE the printer driver should use.  It can get its
  477.                 settings from here.
  478.   outDev        Output VBDEVMODE.  The printer will return its current/default
  479.                 settings here.
  480.   fMode         Flags that tell the printer driver what to do with the data
  481.                 you just sent.  Flags are as follows (any combo can be used)
  482.  
  483.                 DM_IN_BUFFER    Instructs the driver to get its new settings
  484.                                 from the supplied inDev VBDEVMODE
  485.                 DM_OUT_BUFFER   Tells the driver to dump its current settings
  486.                                 into the supplied outDev VBDEVMODE
  487.                 DM_IN_PROMPT    Brings up the printer's own settings dialog
  488.                                 and allows the user to manually change things
  489.                 DM_OUT_DEFAULT  All changes to the printer's settings are to
  490.                                 be written out as the new Windows defaults for
  491.                                 that printer
  492.  
  493. Description:
  494. This is the one you've been waiting for.  This function calls the printer's
  495. ExtDeviceMode() function, allowing you to give the printer new settings, get
  496. its current settings, or update the Windows default settings.
  497.  
  498. Notes:
  499. Do not use the same VBDEVMODE for input as you do for output.  The results may
  500. be unreliable at best.
  501.  
  502. Examples:
  503. i = VBExtDeviceMode(Me.hWnd,DefPrinter$,dmINPUT,dmOUTPUT,DM_OUT_BUFFER)
  504.  
  505. ' Gets the printer's current settings and puts them in dmOUTPUT
  506.  
  507. i = VBExtDeviceMode(Me.hWnd,DefPrinter$,dmINPUT,dmOUTPUT,DM_IN_BUFFER Or
  508. DM_OUT_DEFAULT)
  509.  
  510. ' Tells the printer to use the settings in dmINPUT and to make them the new
  511. ' default settings for the printer
  512.  
  513. i = VBExtDeviceMode(Me.hWnd,DefPrinter$,dmINPUT,dmOUTPUT,DM_IN_BUFFER Or
  514. DM_IN_PROMPT Or DM_OUT_BUFFER)
  515.  
  516. ' Tells the printer driver to bring up its custom dialog using the settings
  517. ' supplied in dmINPUT.  Allows the user to change anything, and the final
  518. ' settings will be placed in dmOUTPUT
  519.  
  520. Returns:
  521. Integer
  522. This function returns whatever the ExtDeviceMode() returns.  Usually IDOK or
  523. IDCANCEL if using the printer's dialog box.  Otherwise it will usually
  524. return 1 for success.  It can return the size of the DEVMODE structure if no
  525. flags are specified in the original function call.  There are two more
  526. returns:
  527.  
  528. False = Unable to open the printer driver
  529. True  = Unable to determine the size of the DEVMODE structure
  530. -----------------------------------------------------------------------------
  531.  
  532. Declare:
  533. Declare Function VBDeviceCapabilities Lib "vbprint.dll" (printername As
  534. String, Cap As Integer, lpszOutput As Any, inDev As DEVMODE_TYPE) As Long
  535.  
  536.  --and (VB4 versions only)--
  537.  
  538. Declare Function VBDeviceCapArray Lib "vbprntxx.dll" Alias
  539. "VBDeviceCapabilities" (printername As String, Cap As Integer, lpszOutput() As
  540. Any, inDev As DEVMODE_TYPE) As Long
  541.  
  542. Inputs:
  543.   printername   The name and port of the printer to query (formatted the
  544.                 same as all the other functions that refer to printers)
  545.   Cap           The particular capability you wish to query.  Cap can be one
  546.                 of the following (taken directly from the Win3.1 SDK)
  547.  
  548.                 Value   Meaning
  549.  
  550. DC_BINNAMES     Copies an array containing a list of the names of the paper
  551.                 bins. This array is in the form char PaperNames[cBinMax]
  552.                 [cchBinName] where cchBinName is 24. If the lpszOutput
  553.                 parameter is NULL, the return value is the number of bin
  554.                 entries required. Otherwise, the return value is the number
  555.                 of bins copied.
  556.  
  557. DC_BINS         Retrieves a list of available bins. The function copies the
  558.                 list to the lpszOutput parameter as a WORD array. If
  559.                 lpszOutput is NULL, the function returns the number of
  560.                 supported bins to allow the application the opportunity to
  561.                 allocate a buffer with the correct size. For more information
  562.                 about these bins, see the description of the dmDefaultSource
  563.                 member of the DEVMODE structure.
  564.  
  565. DC_COPIES       Returns the number of copies the device can print.
  566.  
  567. DC_DRIVER       Returns the version number of the printer driver.
  568.  
  569. DC_DUPLEX       Returns the level of duplex support. The function returns 1 if
  570.                 the printer is capable of duplex printing. Otherwise, the
  571.                 return value is zero.
  572.  
  573. DC_ENUMRESOLUTIONS     Returns a list of available resolutions. If lpszOutput
  574.                 is NULL, the function returns the number of available
  575.                 resolution configurations. Resolutions are represented by
  576.                 pairs of LONG integers representing the horizontal and
  577.                 vertical resolutions (specified in dots per inch).
  578. DC_EXTRA        Returns the number of bytes required for the device-specific
  579.                 portion of the DEVMODE structure for the printer driver.
  580.  
  581. DC_FIELDS       Returns the dmFields member of the printer driver's DEVMODE
  582.                 structure. The dmFields member indicates which fields in the
  583.                 device-independent portion of the structure are supported by
  584.                 the printer driver.
  585.  
  586. DC_FILEDEPENDENCIES    Returns a list of files that also need to be loaded
  587.                 when a driver is installed. If the lpszOutput parameter is
  588.                 NULL, the function returns the number of files. Otherwise,
  589.                 lpszOutput points to an array of filenames in the form
  590.                 char[chFileName, 64]. Each filename is a null-terminated
  591.                 string.
  592.  
  593. DC_MAXEXTENT    Returns a POINT structure containing the maximum paper size
  594.                 that the dmPaperLength and dmPaperWidth members of the printer
  595.                 driver's DEVMODE structure can specify.
  596.  
  597. DC_MINEXTENT    Returns a POINT structure containing the minimum paper size
  598.                 that the dmPaperLength and dmPaperWidth members of the printer
  599.                 driver's DEVMODE structure can specify.
  600.  
  601. DC_ORIENTATION  Returns the relationship between portrait and landscape
  602.                 orientations for a device, in terms of the number of degrees
  603.                 that portrait orientation is rotated counterclockwise to
  604.                 produce landscape orientation. The return value can be one of
  605.                 the following:
  606.  
  607.                 Value   Meaning
  608.  
  609.                  0      No landscape orientation.
  610.                  90     Portrait is rotated 90 degrees to produce landscape.
  611.                         (For example, Hewlett-Packard PCL printers.)
  612.                  270    Portrait is rotated 270 degrees to produce landscape.
  613.                         (For example, dot-matrix printers.)
  614.  
  615. DC_PAPERNAMES  Retrieves a list of supported paper names--for example, Letter
  616.                or Legal. If the lpszOutput parameter is NULL, the function
  617.                returns the number of paper sizes available. Otherwise,
  618.                lpszOutput points to an array for the paper names in the form
  619.                char[cPaperNames, 64]. Each paper name is a null-terminated
  620.                string.
  621.  
  622. DC_PAPERS      Retrieves a list of supported paper sizes. The function copies
  623.                the list to lpszOutput as a WORD array and returns the number
  624.                of entries in the array. If lpszOutput is NULL, the function
  625.                returns the number of supported paper sizes to allow the
  626.                application the opportunity to allocate a buffer with the
  627.                correct size. For more information on paper sizes, see the
  628.                description of the dmPaperSize member of the DEVMODE structure.
  629.  
  630. DC_PAPERSIZE   Copies the dimensions of all supported paper sizes, in tenths
  631.                of a millimeter, to an array of POINT structures pointed to by
  632.                the lpszOutput parameter. The width (x-dimension) and length
  633.                (y-dimension) of a paper size are returned as if the paper
  634.                were in the DMORIENT_PORTRAIT orientation.
  635.  
  636. DC_SIZE        Returns the dmSize member of the printer driver's DEVMODE
  637.                structure.
  638.  
  639. DC_TRUETYPE    Retrieves the abilities of the driver to use TrueType fonts.
  640.                The return value can be one or more of the following:
  641.  
  642.                 Value  Meaning
  643.  
  644.                 DCTT_BITMAP    Device is capable of printing TrueType fonts
  645.                                as graphics. (For example, dot-matrix and PCL
  646.                                printers.)
  647.                 DCTT_DOWNLOAD  Device is capable of downloading TrueType
  648.                                fonts. (For example, PCL and PostScript
  649.                                printers.)
  650.                 DCTT_SUBDEV    Device is capable of substituting device fonts
  651.                                for TrueType fonts. (For example, PostScript
  652.                                printers.)
  653.  
  654.                 For DC_TRUETYPE, the lpszOutput parameter should be NULL.
  655.  
  656. DC_VERSION     Returns the specification version to which the printer driver
  657.                conforms.
  658.  
  659.  
  660.  
  661.   lpszOutput    Usually an array of some type or another (depending on the
  662.                 capability you are querying).  See notes below on how to
  663.                 properly pass an array here.
  664.   InDev         A VBDEVMODE structure.  The printer driver can get its info
  665.                 either from this structure (if filled in) or will get its
  666.                 info from the default settings if you do not fill it in.
  667.  
  668. Description:
  669. This function calls the DeviceCapabilities() printer driver function to query
  670. the printer on a particular feature that it may have.  This can be used to
  671. obtain the list of available paper types, get info on paper bins and even the
  672. types of print resolutions (DPI) available.
  673.  
  674. Notes:
  675. When querying the device on a parameter that returns an array of data, you
  676. should first query it with a 0 lpszOutput parameter.  Example:
  677.  
  678. l = VBDeviceCapabilities(DefPrinter$, DC_PAPERNAMES, ByVal 0&, inDev)
  679.  
  680. This will return the number of papernames the device uses.  The "ByVal 0&" is
  681. very important.  DO NOT USE  NULL  OR FORGET THE "&"!!  The input param will
  682. be expecting a Long, so don't give it anything else.
  683. Once you've DIMmed an array to hold the data, you can then call it again with
  684. the destination array:
  685.  
  686. (VB3 library version)
  687. l = VBDeviceCapabilities(DefPrinter$, DC_PAPERNAMES, Names$(0), inDev)
  688.  
  689. (VB4 16/32 bit library version)
  690. l = VBDeviceCapArray(DefPrinter$, DC_PAPERNAMES, Names$(), inDev)
  691.  
  692. For the VB3 version of this function, always reference the first element in
  693. the array in the function call (in this case, Name$(0) since 0 is typically
  694. the first element in any array).
  695.  
  696. For VB4, do not mention ANY element in the array, just pass the whole array.
  697.  
  698. The VB3 module VBPRINT.BAS (VBPRNT32.BAS for VB4) contains easy-to-use "Types"
  699. (structures) that will make it easier for you to call the queries that return
  700. arrays.  In the VBPRINT.FRM (VBPRNT32.FRM for VB4) file, the Sub ShowOptions
  701. gives several practical examples of making this call using the Type's from
  702. the .BAS file.
  703.  
  704. Returns:
  705. Long
  706. False = Failure
  707. Anything else is success.
  708. -----------------------------------------------------------------------------
  709.  
  710. Declare:
  711. Declare Function VBResetDC(ByVal hDC As Integer, outDev As DEVMODE_TYPE) As
  712. Integer
  713.  
  714. Inputs:
  715.   hDC           The device context to reset
  716.   outDev        A new DEVMODE structure containing any new settings to give
  717.                 the opened device
  718.  
  719. Description:
  720. The VBResetDC function updates the given device context, based on the
  721. information in the specified DEVMODE structure.  Among other things, this
  722. command can be used to change the paper orientation or paper bins during a
  723. print session.
  724.  
  725. Returns:
  726. Integer
  727. The return value is the handle of the original device context if the function
  728. is successful.  Otherwise, it is False.
  729. -----------------------------------------------------------------------------
  730.  
  731.  
  732. Robert Simpson
  733. Programmer at Large
  734. BC Software
  735. Phx, AZ
  736. simpson@primenet.com
  737.